import request from '@/utils/http'
import type { responseHoscodeType, responseDepartmentType, responseRuleDataType, responseWorkListDataType, responseWorkDataType } from './type'

// 枚举接口地址
enum API {
  // 获取医院列表
  HOSPITAL_URL = '/hosp/hospital',
  //根据医院名称获取医院列表
  HOSNAME_URL = '/hosp/hospital/findByHosname',
  //医院预约挂号详情
  HOSCODE_URL = HOSPITAL_URL,
  // 获取医院科室列表
  DEPARTMENT_URL = '/hosp/hospital/department',
  // 获取可预约排班数据
  BOOKINGSCHEDULERULE_URL = '/hosp/hospital/auth/getBookingScheduleRule',
  //获取排班数据
  FINDSCEDULELIST_URL = '/hosp/hospital/auth/findScheduleList',
  // 根据排班id获取排班数据 GET /api/hosp/hospital/getSchedule/{scheduleId}
  GETSCHEDULE_URL = '/hosp/hospital/getSchedule',
}

/**
 *  获取医院分页筛选列表
 *
 * @param page {number} 当前页码
 * @param limit {number} 每页记录数
 * @param params { object } 其他参数
 */
export const getHospitalsAPI = (page: number, limit: number, params: object = {}) => {
  return request({
    url: API.HOSPITAL_URL + `/${page}/${limit}`,
    method: 'get',
    params,
  })
}

/**
 * 根据医院名称获取医院列表
 *
 * @param hosname {string} 医院名称
 */
export const getHosNameAPI = (hosname: string) => {
  return request({
    url: API.HOSNAME_URL + `/${hosname}`,
  })
}

/**
 * 医院预约挂号详情
 *
 * @param hoscode {string} 医院 code
 * @returns {responseHoscodeType}
 */
export const getHosCodeAPI = (hoscode: string) => {
  return request<any, responseHoscodeType>({
    url: API.HOSCODE_URL + `/${hoscode}`,
  })
}

/**
 * 获取医院科室列表
 *
 * @param hoscode {string} 医院唯一 code
 * @returns {responseDepartmentType}
 */
export const getDepartmentAPI = (hoscode: string) => {
  return request<any, responseDepartmentType>({
    url: API.DEPARTMENT_URL + `/${hoscode}`,
  })
}

/** 获取可预约排班数据
 *
 * @param page {number} 当前页码
 * @param limit {number} 每页记录数
 * @param hoscode {string} 医院code
 * @param depcode {string} 科室code
 */
export const getBookingScheduleRuleAPI = (page: number, limit: number, hoscode: string, depcode: string) => {
  return request<any, responseRuleDataType>({
    url: API.BOOKINGSCHEDULERULE_URL + `/${page}/${limit}/${hoscode}/${depcode}`,
  })
}

/**
 * 获取排班数据
 *
 * @param hoscode {string} 医院code
 * @param depcode {string} 科室 code
 * @param workDate {string} 排班日期
 */
export const getFindScheduleListAPI = (hoscode: string, depcode: string, workDate: string) => {
  return request<any, responseWorkListDataType>({
    url: API.FINDSCEDULELIST_URL + `/${hoscode}/${depcode}/${workDate}`,
  })
}

/**
 * 根据排班id获取排班数据
 *
 * @param scheduleId {string} 排班id
 */
export const gainSchedulingDataAPI = (scheduleId: string) => {
  return request<any, responseWorkDataType>({
    url: API.GETSCHEDULE_URL + `/${scheduleId}`,
  })
}
